import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout'
Vue.use(VueRouter)

// 导入配置的动态路由
import HoutaiRoute from './modules/houtai'
import QiyeRoute from './modules/qiye'
import TikuRoute from './modules/tiku'
import XuekeRoute from './modules/xueke'
import SkillRoute from './modules/skill'

const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 动态路由
export const asyncRoutes = [
  HoutaiRoute,
  QiyeRoute,
  TikuRoute,
  XuekeRoute,
  SkillRoute
]


// 静态路由
export const constRoutes = [
  {
    path: '/',
    name: 'dashboard',
    component: Layout,
    meta: { title: '面板' },
    redirect: '/dashboard',
    children: [
      {
        path: '/dashboard',
        name: 'dashboard',
        component: () => import('@/views/dashboard'),
        meta: { title: '面板', icon: 'fa-dashboard' },
        hidden: true
      }

    ]
  },
  {
    path: '/login',
    component: () => import("@/views/login"),
    meta: { title: '登录' },
    hidden: true

  },


]


// 重置路由
const createRouter = () => new VueRouter({
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constRoutes] // 临时合并所有的路由
})
const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}
export default router

